/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Ecu911_Interfaz;

import Ecu911_Excepciones.ExceptionSql;
import Ecu911_Excepciones.ValoresNulos;
import Ecu911_Negocio.NegInstituciones;
import Ecu911_Negocio.NegSectorInstitucion;
import Ecu911_Negocio.NegSectores;
import java.awt.Frame;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.DefaultListModel;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

import Ecu911_Negocio_Patrones.ClaseSingleton;

/**
 *
 * @author User
 */
public class FrmMantenimientoInstitucionesServicios extends javax.swing.JDialog {

    String institucionCreada;
    NegInstituciones miInstitucion;
    NegSectores miSector;
    NegSectorInstitucion miSectorInsttucion;
    DefaultTableModel temp;
    ArrayList listaInstituciones;
    private Frame pasoElFramePrincipal;
    DefaultListModel modeloLista;
    ArrayList sectoresInstitucionSeleccionada;
    ArrayList sectoresCompletos;
    public static int idInstitucionSeleccionada;
    /**
     * Creates new form FrmMantenimientoInstitucionesServicios
     */
    public FrmMantenimientoInstitucionesServicios(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        temp = (DefaultTableModel)this.tablaInstituciones.getModel();
        listaInstituciones = new ArrayList();
        FrmPrincipal.historialUsuario = ClaseSingleton.getmiClaseSingleton().getContenido();
        ClaseSingleton.getmiClaseSingleton().setContenidos(FrmPrincipal.historialUsuario);
    }
    
    private void imprimirMensajeError(String msj){
       JOptionPane.showConfirmDialog(null,msj,
       "ERROR DE SISTEMA",JOptionPane.DEFAULT_OPTION,JOptionPane.ERROR_MESSAGE,null); 
   }
   

    private void inhabilitarTextos(){
        this.txtDireccionInstitucion.setEditable(false);
        this.txtNombreInstitucion.setEditable(false);
       
   }
    
   private void imprimirMensajeAcciónRealizada(String msj){
       JOptionPane.showConfirmDialog(null,msj,
       "ACCION DE SISTEMA",JOptionPane.DEFAULT_OPTION,JOptionPane.INFORMATION_MESSAGE,null); 
   }
   
   private void validarInformaciónNuevoRegistro(boolean val)throws ValoresNulos, ExceptionSql, SQLException{
        if (val){
            this.guardarNuevoRegistro();
        }
        else{
            throw new ValoresNulos();
        }
    }
   
   private boolean existeRegistro(){
       for(int i = 0; i < listaInstituciones.size(); i++){
           if(listaInstituciones.get(i).equals(institucionCreada.toUpperCase()))
               return true;
       }
       return false;
   }
   
   private void guardarNuevoRegistro()throws ExceptionSql, SQLException{
       try{
            miInstitucion = new NegInstituciones(this.institucionCreada.toUpperCase());
            miInstitucion.guardarMiInstitucionDB();
            
        }
        catch(ExceptionSql e){
            throw new ExceptionSql("Error en la base de datos. \nNo se pudo almacenar información.");
        }       
    }
   
   private void cargarTabla(){
        miInstitucion = new NegInstituciones();
        miInstitucion.cargarMiInstitucionDB();
        listaInstituciones = miInstitucion.cargarTabla();
        for (int i = tablaInstituciones.getRowCount() - 1; i >= 0; i--) {
            temp.removeRow(i);
        }
            for (int i = 0; i < listaInstituciones.size(); i++) {
                Object nuevo[] = {listaInstituciones.get(i)}; //esto es por las tres columnas aunque puede variar
                temp.addRow(nuevo);
        }
        tablaInstituciones.setModel(temp); 
   }
   
   

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel2 = new javax.swing.JPanel();
        jLabel8 = new javax.swing.JLabel();
        jPanel3 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        txtBuscarInstitucion = new javax.swing.JTextField();
        btnBuscar = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        tablaInstituciones = new javax.swing.JTable();
        jPanel4 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        txtNombreInstitucion = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        listaSectoresInsttucion = new javax.swing.JList();
        txtDireccionInstitucion = new javax.swing.JTextField();
        btnAgregarSector = new javax.swing.JButton();
        jLabel6 = new javax.swing.JLabel();
        jScrollPane3 = new javax.swing.JScrollPane();
        listaTelefonosInstitucion = new javax.swing.JList();
        jPanel1 = new javax.swing.JPanel();
        btnNuevaInstitucion = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("ECU911 - [Mantenimiento Instituciones]");
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowOpened(java.awt.event.WindowEvent evt) {
                formWindowOpened(evt);
            }
        });

        jPanel2.setBackground(new java.awt.Color(255, 102, 0));

        jLabel8.setForeground(new java.awt.Color(255, 255, 255));
        jLabel8.setText("Información genaral de las instituciones asociadas al Sistema ECU911.");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jLabel8)
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap(25, Short.MAX_VALUE)
                .addComponent(jLabel8)
                .addContainerGap())
        );

        jPanel3.setBackground(new java.awt.Color(255, 255, 255));
        jPanel3.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jLabel1.setText("Busqueda rápida:");

        btnBuscar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Iconos/BuscarTabla.png"))); // NOI18N

        tablaInstituciones.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "INSTITUCIONES"
            }
        ));
        tablaInstituciones.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tablaInstitucionesMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(tablaInstituciones);

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addGap(18, 18, 18)
                        .addComponent(txtBuscarInstitucion, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(btnBuscar)
                        .addGap(0, 54, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(btnBuscar)
                    .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel1)
                        .addComponent(txtBuscarInstitucion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(18, 18, 18)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel4.setBackground(new java.awt.Color(255, 255, 255));
        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), "Información General."));

        jLabel2.setText("Nombre Institución:");

        jLabel3.setText("Sectores de ubicación:");

        jLabel4.setText("Dirección:");

        jLabel5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Iconos/MapaCuenca.png"))); // NOI18N

        listaSectoresInsttucion.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                listaSectoresInsttucionMouseClicked(evt);
            }
        });
        jScrollPane2.setViewportView(listaSectoresInsttucion);

        btnAgregarSector.setText("Asignar Sector a la Institución");
        btnAgregarSector.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAgregarSectorActionPerformed(evt);
            }
        });

        jLabel6.setText("Teléfonos:");

        jScrollPane3.setViewportView(listaTelefonosInstitucion);

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(jPanel4Layout.createSequentialGroup()
                                .addGap(0, 0, Short.MAX_VALUE)
                                .addComponent(jLabel5))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel4Layout.createSequentialGroup()
                                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel4)
                                    .addComponent(jLabel6))
                                .addGap(18, 18, 18)
                                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jPanel4Layout.createSequentialGroup()
                                        .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 148, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(0, 0, Short.MAX_VALUE))
                                    .addComponent(txtDireccionInstitucion))))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
                            .addComponent(btnAgregarSector, javax.swing.GroupLayout.DEFAULT_SIZE, 201, Short.MAX_VALUE)))
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel3)
                            .addComponent(jLabel2))
                        .addGap(18, 18, 18)
                        .addComponent(txtNombreInstitucion, javax.swing.GroupLayout.PREFERRED_SIZE, 300, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(txtNombreInstitucion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(jLabel3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jScrollPane2)
                    .addComponent(jLabel5))
                .addGap(18, 18, 18)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(txtDireccionInstitucion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnAgregarSector))
                .addGap(18, 18, 18)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 77, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel1.setBackground(new java.awt.Color(255, 255, 255));
        jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jPanel1.setToolTipText("");

        btnNuevaInstitucion.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Iconos/NuevaInstitucion.png"))); // NOI18N
        btnNuevaInstitucion.setText("Nuevo");
        btnNuevaInstitucion.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnNuevaInstitucion.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnNuevaInstitucion.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnNuevaInstitucionActionPerformed(evt);
            }
        });

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Iconos/salir2.png"))); // NOI18N
        jButton1.setText("Salir");
        jButton1.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton1.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(btnNuevaInstitucion)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jButton1)
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(btnNuevaInstitucion, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnNuevaInstitucionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnNuevaInstitucionActionPerformed
        FrmPrincipal.historialUsuario = FrmPrincipal.historialUsuario + "\nINGRESO OPCION NUEVA INSTITUCION.";
        ClaseSingleton.getmiClaseSingleton().setContenidos(FrmPrincipal.historialUsuario);
       institucionCreada = (String)JOptionPane.showInputDialog(null,"Ingrese nombre nueva institución","NUEVO REGISTRO",JOptionPane.INFORMATION_MESSAGE); 
       if(existeRegistro()){
           this.imprimirMensajeError("Error al registrar. \nLa institución ya fue creada.");
       }
       else{
            try {
                this.validarInformaciónNuevoRegistro(this.validarCamposTextoCompleto());
                this.imprimirMensajeAcciónRealizada("Información correcta. \nLa institución fue creada.");
                this.cargarTabla();
            } catch (ValoresNulos ex) {
                this.imprimirMensajeError(ex.getMessage());
            } catch (ExceptionSql ex) {
                this.imprimirMensajeError(ex.getMessage());
            } catch (SQLException ex) {
                this.imprimirMensajeError(ex.getMessage());
            }          
       }
    }//GEN-LAST:event_btnNuevaInstitucionActionPerformed

   private boolean validarCamposTextoCompleto(){
       boolean check = true;
       if(this.institucionCreada.compareTo("")==0)
       {
           check = false;
       }
       return check;
   }
      
   private void cargarSectoresDeInstitucion(int id){
       sectoresCompletos = new ArrayList();
       miSectorInsttucion = new NegSectorInstitucion();
       miSectorInsttucion.setIdInstitucion(id);
       sectoresInstitucionSeleccionada = miSectorInsttucion.cargarSectoresInstitucionDB();
       modeloLista = new DefaultListModel();
       for (int i=0; i<sectoresInstitucionSeleccionada.size(); i++){
           miSector = new NegSectores();
           miSector.setIdInstitucion(sectoresInstitucionSeleccionada.get(i).toString());
           miSector.cargarMiInstitucionDB();
           modeloLista.addElement(miSector.getNomInstitucion());
           sectoresCompletos.add(miSector);
       } 
       this.txtNombreInstitucion.setText(tablaInstituciones.getValueAt(id-1, 0).toString());
       listaSectoresInsttucion.setModel(modeloLista);
   }
   
    private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened
        cargarTabla();  
        inhabilitarTextos();
    }//GEN-LAST:event_formWindowOpened

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        this.dispose();
    }//GEN-LAST:event_jButton1ActionPerformed

    private void btnAgregarSectorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAgregarSectorActionPerformed
        FrmPrincipal.historialUsuario = FrmPrincipal.historialUsuario + "\nSELECCIONO OPCION NUEVO SECTOR";
        ClaseSingleton.getmiClaseSingleton().setContenidos(FrmPrincipal.historialUsuario);
        FrmMantenimientoSectores sectores1 = new FrmMantenimientoSectores(pasoElFramePrincipal, true);
        sectores1.setVisible(true);
        this.dispose();
        
    }//GEN-LAST:event_btnAgregarSectorActionPerformed

    private void tablaInstitucionesMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tablaInstitucionesMouseClicked
        idInstitucionSeleccionada = tablaInstituciones.rowAtPoint(evt.getPoint())+1;
        cargarSectoresDeInstitucion(idInstitucionSeleccionada);
        DefaultListModel mdl = new DefaultListModel();
        mdl.clear();
        listaTelefonosInstitucion.setModel(mdl);
        this.txtDireccionInstitucion.setText("");
    }//GEN-LAST:event_tablaInstitucionesMouseClicked

    private void listaSectoresInsttucionMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_listaSectoresInsttucionMouseClicked
        String sectorSeleccionadoLista = listaSectoresInsttucion.getSelectedValue().toString();
        int id = 0;
        for(int i=0; i<sectoresCompletos.size(); i++){
            miSector = new NegSectores();
            miSector = (NegSectores) sectoresCompletos.get(i);
            if(sectorSeleccionadoLista.compareTo(miSector.getNomInstitucion().toString())==0){
                id = Integer.parseInt(miSector.getIdInstitucion());
            }
        }
        miSectorInsttucion.setIdSector(id);
        miSectorInsttucion.setIdInstitucion(idInstitucionSeleccionada);
        miSectorInsttucion.cargarMiSectorInstitucionDB();
        this.txtDireccionInstitucion.setText(miSectorInsttucion.getDireccion());
        DefaultListModel mdl = new DefaultListModel();
        mdl.addElement(miSectorInsttucion.getTelefono1());
        mdl.addElement(miSectorInsttucion.getTelefono2());
        mdl.addElement(miSectorInsttucion.getTelefono3());
        listaTelefonosInstitucion.setModel(mdl);
    }//GEN-LAST:event_listaSectoresInsttucionMouseClicked

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(FrmMantenimientoInstitucionesServicios.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(FrmMantenimientoInstitucionesServicios.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(FrmMantenimientoInstitucionesServicios.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(FrmMantenimientoInstitucionesServicios.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the dialog */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                FrmMantenimientoInstitucionesServicios dialog = new FrmMantenimientoInstitucionesServicios(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAgregarSector;
    private javax.swing.JButton btnBuscar;
    private javax.swing.JButton btnNuevaInstitucion;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JList listaSectoresInsttucion;
    private javax.swing.JList listaTelefonosInstitucion;
    private javax.swing.JTable tablaInstituciones;
    private javax.swing.JTextField txtBuscarInstitucion;
    private javax.swing.JTextField txtDireccionInstitucion;
    private javax.swing.JTextField txtNombreInstitucion;
    // End of variables declaration//GEN-END:variables
}
